package by.imotaeva.printing_services.services.impl;

import javax.annotation.PostConstruct;
import javax.inject.Inject;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import by.imotaeva.printing_services.dataaccess.DesignExampleImgDao;
import by.imotaeva.printing_services.datamodel.DesignExampleImg;
import by.imotaeva.printing_services.services.DesignExampleImgService;

@Service
public class DesignExampleImgServiceImpl implements DesignExampleImgService {
	private static final Logger LOGGER = LoggerFactory
			.getLogger(DesignExampleImgServiceImpl.class);

	@Inject
	private DesignExampleImgDao dao;

	@PostConstruct
	private void init() {
		// this method will be called by Spring after bean instantiation. Can be
		// used for any initialization process.
		LOGGER.info(
				"Instance of DesignExampleImgService is created. Class is: {}",
				getClass().getName());
	}

	@Override
	public DesignExampleImg get(Long id) {
		DesignExampleImg entity = dao.getById(id);
		return entity;
	}

	@Override
	public void saveOrUpdate(DesignExampleImg entity) {
		if (entity.getId() == null) {
			LOGGER.debug("Save new: {}", entity);
			dao.insert(entity);
		} else {
			LOGGER.debug("Update: {}", entity);
			dao.update(entity);
		}

	}

	@Override
	public void delete(DesignExampleImg entity) {
		LOGGER.debug("Remove: {}", entity);
		dao.delete(entity.getId());

	}

	@Override
	public void deleteAll() {
		LOGGER.debug("Remove all Design Example Imgs");
		dao.deleteAll();

	}

}
